package com.yuren.codecrushlearn.Q5200;


import java.util.LinkedList;
import java.util.List;

/**
 * Created with Intellij IDEA.
 * Description:
 * 基于链表实现的哈希集合
 * @author Sleepy Code Tom
 * @date 2025-04-19 23:49
 */
public class Q5212 {
    List<Integer>[] linkedLists = new LinkedList[16];

    int bucketSize = 16;

    public void add(int key) {
        int index = key % bucketSize;
        if (linkedLists[index] == null) {
            linkedLists[index] = new LinkedList<>();
        }
        if (!linkedLists[index].contains(key)) {
            linkedLists[index].add(key);
        }
    }


    public boolean contains(Integer key) {
        int index = key % bucketSize;
        if (linkedLists[index] == null) {
            return false;
        }
        return linkedLists[index].contains(key);
    }

    void remove(int key) {
        int index = key % bucketSize;
        if (linkedLists[index] != null) {
            linkedLists[index].remove((Integer) key);
        }
    }
}
